# get ic decay
from get_data import get_data,bars
from singletrader.processors.cs_processor import CsWinzorize
from singletrader.shared.utility import save_pkl
from singletrader.factorlib import FactorEvaluation,summary_plot
import pandas as pd
import plotly.express as px
from plotly.figure_factory import create_table
import warnings
warnings.filterwarnings('ignore')
data = get_data().dropna()
features = [_f for _f in data.columns if _f not in bars]
liquidity_group = data.groupby(level=0).apply(lambda x:pd.qcut(x['amount3M'],3,labels=['low','medium','high'])).droplevel(0)
ep_group = data.groupby(level=0).apply(lambda x:pd.qcut(x['ep'],3,labels=['low','medium','high'])).droplevel(0)
# data['adjskew'] = cs_win(data['skew'])
fe = FactorEvaluation(bar_data=data[bars],factor_data=data[features],freq=12)
ic_summary= fe.get_ic_summary(add_shift=0,base='close')
ic_summary2 = fe.get_ic_summary(add_shift=0,base='close',next_n=3)
adjskew:将两边尾部5%的值用中位数替代
#未来一个月
round(ic_summary,4)
| skew_1 | adjskew_1 | distance_1 | mom6x3_1 | mom9x3_1 | mom12x3_1 | mom1M_1 | mom2M_1 | mom3M_1 | mom6M_1 | turnover3M_1 | amount3M_1 | stddev_diff_1 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| raw | ic.mean | -0.022 | -0.0251 | 0.0015 | 0.0014 | 0.0075 | 0.0093 | -0.0409 | -0.0495 | -0.0438 | -0.0324 | -0.0417 | -0.0416 | -0.0079 |
| ic.t-stats | -4.587 | -5.4944 | 0.1332 | 0.1753 | 0.8213 | 0.9784 | -4.4306 | -4.6343 | -4.2191 | -3.0323 | -3.7078 | -4.6622 | -1.4904 | |
| ind_neu | ic.mean | -0.022 | -0.0253 | 0.0087 | -0.0009 | 0.0018 | 0.0015 | -0.0489 | -0.0542 | -0.0494 | -0.0381 | -0.0435 | -0.0419 | -0.0095 |
| ic.t-stats | -5.254 | -6.3401 | 0.8645 | -0.1374 | 0.2500 | 0.1945 | -6.2776 | -6.0066 | -5.5063 | -4.2280 | -4.6661 | -5.4407 | -2.1090 |
#未来三个月(culmulative)
round(ic_summary2,4)
| skew_3 | adjskew_3 | distance_3 | mom6x3_3 | mom9x3_3 | mom12x3_3 | mom1M_3 | mom2M_3 | mom3M_3 | mom6M_3 | turnover3M_3 | amount3M_3 | stddev_diff_3 | ||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| raw | ic.mean | -0.0195 | -0.0213 | -0.0230 | 0.0064 | 0.0036 | -0.0001 | -0.0369 | -0.0390 | -0.0381 | -0.0254 | -0.0613 | -0.0653 | -0.0096 |
| ic.t-stats | -2.7490 | -3.0131 | -1.3832 | 0.5220 | 0.2561 | -0.0064 | -2.6073 | -2.6246 | -2.6439 | -1.6507 | -3.8074 | -4.2297 | -1.1795 | |
| ind_neu | ic.mean | -0.0211 | -0.0228 | -0.0143 | 0.0009 | -0.0046 | -0.0098 | -0.0424 | -0.0449 | -0.0433 | -0.0333 | -0.0632 | -0.0654 | -0.0095 |
| ic.t-stats | -3.5549 | -3.8590 | -0.9877 | 0.0915 | -0.4076 | -0.7771 | -3.6622 | -3.6585 | -3.5429 | -2.6066 | -4.8169 | -4.7144 | -1.4497 |
收益曲线和表格指标,均是针对超额收益,benchmark用的是equal weighted
factor='mom3M'
report = fe.get_factor_detail_report(factor=factor,add_shift=0,base='close',total=False,excess_return=True,holding_period=1)
summary_plot(report)
group_ic = fe.factor_ana(factor=factor,ep_group=ep_group,liquidity_group=liquidity_group)
bar = px.bar(group_ic['ic.mean'].reset_index(),x='level_1',y='ic.mean',color='level_0',barmode='group',title='ic of different ep & lquidity')
bar.show()